package cn.ware.house.interfaces.service.productservice.impl;

import cn.ware.house.interfaces.entity.goods.ProductCategory;
import cn.ware.house.interfaces.mapper.prodctmapper.ProductCategoryMapper;
import cn.ware.house.interfaces.service.productservice.ProductCategoryService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

@Service
public class ProductCategoryServiceImpl implements ProductCategoryService {
    @Resource
    private ProductCategoryMapper productCategoryMapper;

    @Override
    public ProductCategory findProductCategoryByIdWithChildren(Integer id) {
        return productCategoryMapper.selectProductCategoryByIdWithChildren(id);
    }

    @Override
    public List<ProductCategory> findRootProductCategories() {
        return productCategoryMapper.selectRootProductCategories();
    }

    @Override
    public List<ProductCategory> findChildrenCategoriesByParentId(Integer parentId) {
        return productCategoryMapper.selectChildrenCategoriesByParentId(parentId);
    }

    @Override
    public boolean insertProductCategory(ProductCategory productCategory) {
        int rows = productCategoryMapper.insertProductCategory(productCategory);
        return rows > 0;
    }

    @Override
    public boolean updateProductCategoryById(ProductCategory productCategory) {
        int rows = productCategoryMapper.updateProductCategoryById(productCategory);
        return rows > 0;
    }

    @Override
    public boolean deleteProductCategoriesByIds(List<Integer> categoryIds) {
        int affectedRows = productCategoryMapper.deleteProductCategoriesByIds(categoryIds);
        return affectedRows == categoryIds.size();
    }
}